package com.roger.springcloudGreenwich.service.impl;

import java.io.IOException;
import java.io.InputStream;

public class RuntimeTest {
    public static void main(String[] args) {
        RuntimeTest s = new RuntimeTest();
        s.test();
    }
    public void test(){
        Runtime run =Runtime.getRuntime();
        try {
            Process p = run.exec("ping 127.0.0.1");
            InputStream ins = p.getInputStream();
            new Thread(new inputStreamThread(ins)).start();
            p.waitFor();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    class inputStreamThread implements Runnable{
        private InputStream ins;
        public inputStreamThread(InputStream ins){
            this.ins = ins;

        }
        @Override
        public void run() {
            byte[] b = new byte[100];
            try {

                while((ins.read(b))!=-1){
                    System.out.println(new String(b,"gb2312"));
                    //logger.info(new String(b,"gb2312"));
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

